﻿using DocumentFormat.OpenXml.Lite.Core.Office;
using DocumentFormat.OpenXml.Lite.Shared;
using DocumentFormat.OpenXml.Lite.SpreadsheetML.Excel.Base;
using DocumentFormat.OpenXml.Lite.SpreadsheetML.Excel.RunProperties;
using DocumentFormat.OpenXml.Lite.SpreadsheetML.Excel.Types;
using DocumentFormat.OpenXml.Lite.SpreadsheetML.Excel.WorksheetElements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Samples.Excel
{
    class CellContents
    {
        public static void Create()
        {
            Workbook wb = DocumentManager.Instance.CreateSpreadsheet();

            Worksheet sheet1 = wb.CreateWorksheet("Sheet1", null);

            Cell c1 = sheet1.CreateCell(1, 1);
            c1.CellType = ST_CellType.InlineString;
            c1.InlineRichText = new InlineRichText()
            {
                Text = new SimpleText("Hello world!")
            };

            Cell c2 = sheet1.CreateCell(1, 2);
            c2.CellType = ST_CellType.InlineString;
            RichTextRun r1 = new RichTextRun() 
            {
                Text = new SimpleText("Hello world!")
            };
            r1.AddProperty(new Bold());
            c2.InlineRichText = new InlineRichText();
            c2.InlineRichText.Runs.Add(r1);

            Cell c3 = sheet1.CreateCell(3, 1);
            c3.CellType = ST_CellType.Number;
            c3.AddSimpleText("10.23");

            Cell c4 = sheet1.CreateCell(2, 2);
            c4.CellType = ST_CellType.Boolean;
            c4.AddSimpleText("1");

            Cell c5 = sheet1.CreateCell(2, 3);
            c5.CellType = ST_CellType.Boolean;
            c5.AddSimpleText("0");

            Cell c6 = sheet1.CreateCell(4, 1);
            c6.CellType = ST_CellType.String;
            c6.AddSimpleText("Hello World!");

            wb.Save(@"samples\cellcontents.xlsx");

            Workbook parsed = null;
            if (DocumentManager.Instance.OpenExcelDocument(@"samples\cellcontents.xlsx", out parsed))
            {
                Console.WriteLine("Sample created and parsed succesfully!");
            }
            Console.ReadLine();
        }
    }
}
